//
//  CLAudioPlayer.m
//  AVAudioPlayerDemo
//
//  Created by 周文成 on 2018/1/3.
//  Copyright © 2018年 C-LOVE. All rights reserved.
//

#import "CLAudioPlayer.h"


@interface CLAudioPlayer () <AVAudioPlayerDelegate>

@property (nonatomic, strong) AVAudioPlayer *player;

@end


@implementation CLAudioPlayer

+ (instancetype)sharedInstance {
    static CLAudioPlayer *object = nil;
    if (! object) {
        object = [[self alloc] init];
    }
    return object;
}

 

- (BOOL)playerWithPath:(NSString *)path {
    NSURL *url = [NSURL fileURLWithPath:path];
    if(url == nil) {
        return NO;
    }
    self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    self.player.delegate = self;
    [self.player prepareToPlay];
    [self.player play]; 
    return YES;
}


/** 播放完成的时候调用 */
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
    NSLog(@"%s", __func__);
}

/** 解码错误 */
- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError * __nullable)error {
    NSLog(@"%s", __func__);
}

/** 音频播放过程程中被中断 */
- (void)audioPlayerBeginInterruption:(AVAudioPlayer *)player {
    NSLog(@"%s", __func__);
}

/** 当中断结束的时候 */
- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player withOptions:(NSUInteger)flags {
    NSLog(@"%s", __func__);
}



@end





